import { Button, message } from 'antd';
import React, { Component } from 'react';
import AddressOnLoadSelection from '../../components/address/AddressOnLoadSelection';

import * as rest from '../../lib/rest' ;

export default class Phonograph extends Component{

    constructor(props){
        super(props);
        this.state={
            recordingStatus: '开始录音',
            recordId:''
        }
        
    }

    componentDidMount() {

        rest.getWithOutParam("/recBase/all").then((data)=>{
            console.log(data)
        }).catch(()=>{
            console.log("获取失败");
        })
    }

    testJDBC = ()=>{
        rest.getWithOutParam(`/jdbc/getData`).then((data)=>{
            if(data){
                alert(data);
            }
        })
    }

    testuser = ()=>{
        rest.getWithOutParam(`/user/userInfo`).then((data)=>{
            if(data){
                alert(data);
            }
        })
    }
    onChange = (value)=> {
        console.log('onChange ', value);
        this.setState({ value });
    };

    startRecording= ()=>{
        if(this.state.recordingStatus ==='开始录音'){
            rest.getWithOutParam("/recHandler/startRecording").then((data)=>{
                debugger;
                message.info(data)
                this.setState({
                    recordingStatus:'正在录音:点击停止',
                    recordId:data
                })
            })
        }
        if(this.state.recordingStatus ==='正在录音:点击停止'){
            rest.getWithOutParam(`/recHandler/stopRecording/${this.state.recordId}`).then(()=>{
                message.success("录音结束")
                this.setState({
                    recordingStatus:'开始录音'
                })
            })
        }
    }
    
    stopRecording= ()=>{
        rest.getWithOutParam("/recHandler/stopRecording");
    }

    render(){
        return(
            <div>
                <AddressOnLoadSelection/>
                <Button onClick={this.testJDBC}> 测试</Button>
                <Button onClick={this.testuser}> 用户信息</Button>
                <Button onClick={this.startRecording}> {this.state.recordingStatus}</Button>
                <Button onClick={this.stopRecording}> 结束录音</Button>
                <p>基础样式</p>
            </div>
        )
    }
}
